# -*- coding: utf-8 -*-
# @Time : 2018/12/24 21:12
# @Author : Administrator
# @File : read_data.py
# @Project : python
# @title : Excel数据读取优化封装
import xlrd
class Read_Excel():
    def excel(self,path,sheet_num):
        # print(path)
        book = xlrd.open_workbook(path)  ## 读取Excel
        # print(book)
        sheet = book.sheets()      ## 文件中所有的sheet
        # print(sheet)
        num = sheet[sheet_num-1]     ## 选择第几个sheet,因为是下标取，所以每次减1
        nrow = num.nrows           ## 返回表中有多少行
        # print(nrow)   #3
        ncols =  num.ncols         ## 返回表中的列
        # print(ncols)   #5
        li = []
        for i in range(1,nrow):
            dict = {}
            for j in range(ncols):
                key_name  = num.cell(0,j).value
                key_value = num.cell(i,j).value
                # print(key_name,key_value)
                dict[key_name] = key_value
            li.append(dict)
        return li

if __name__ == '__main__':
    a = Read_Excel()
    print(a.excel(r"E:\41\python\WoniuBoss\Interface\data\test_data.xlsx",1))
